<template>
	<view v-if="realname">
		<view class="login bg-white">
			<u-field label="姓名" placeholder="" :disabled="realname.status>=0" v-model="form.realname"></u-field>
			<u-field label="身份证号" placeholder="" :disabled="realname.status>=0" v-model="form.idcard"></u-field>
		</view>
		
		<view v-show="realname.status==-1 || realname.status==-2">
			<view class="bg-white flex-row justify-around" style="padding: 24rpx 0;">
				<view class="flex-col justify-around align-center" style="width: 50%;height: 300rpx;">
					<view>身份证人像面</view>
					<u-upload :action="$store.state.upload" upload-text="上传图片" :form-data="{type: 'realname'}"
					 :max-count="1" ref="uUpload1" @on-choose-complete="pro1=true" @on-uploaded="onUploaded1" :show-progress="pro1" :header="header"></u-upload>
				</view>
				<view class="flex-col justify-around align-center" style="width: 50%;height: 300rpx;">
					<view>身份证国徽面</view>
					<u-upload :action="$store.state.upload" upload-text="上传图片" :form-data="{type: 'realname'}"
					 :max-count="1" ref="uUpload2" @on-choose-complete="pro2=true" @on-uploaded="onUploaded2" :show-progress="pro2" :header="header"></u-upload>
				</view>
			</view>
		</view>
		
		<view v-show="realname.status!=-1 && realname.status!=-2">
			<view class="bg-white flex-row justify-around" style="padding: 24rpx 0;">
				<view class="flex-col justify-around align-center" style="width: 50%;height: 300rpx;">
					<view>身份证人像面</view>
					<image :src="realname.idcard_front" style="width: 50%;" mode="widthFix"></image>
				</view>
				<view class="flex-col justify-around align-center" style="width: 50%;height: 300rpx;">
					<view>身份证国徽面</view>
					<image :src="realname.idcard_back" style="width: 50%;" mode="widthFix"></image>
				</view>
			</view>
		</view>
		
		<my-btn gold style="margin: 60rpx auto;" @click="submit" v-if="realname.status==-1 || realname.status==-2">提交</my-btn>
		
		<my-btn gold style="margin: 60rpx auto;" disabled @click="submit" v-if="realname.status!=-1 && realname.status!=-2">{{realname.status==0?'审核中':'已通过'}}</my-btn>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					realname: '',
					idcard: '',
					idcard_front: '',
					idcard_back: ''
				},
				realname: '',
				pro1: true,
				pro2: true,
			};
		},
		onLoad() {
			this.header = {
				Authorization: 'Bearer ' + this.$store.state.token
			}
			this.getData();
		},
		methods: {
			onUploaded1(e) {
				this.form.idcard_front = e[0].response.result.src
				this.pro1 = false
			},
			onUploaded2(e) {
				this.form.idcard_back = e[0].response.result.src
				this.pro2 = false
			},
			getData() {
				this.$u.get('/member/realname/info').then(res => {
					let realname = res.data.result.realname
					this.realname = realname
					this.form.realname = realname.realname
					this.form.idcard = realname.idcard
				})
			},
			submit() {
				this.$u.post('/member/realname', this.form).then(res => {
					this.$msg(res.data.msg)
					if (res.data.code==0) {
						this.$msg(res.data.msg, 1000, true).then(res => {
							this.$goto('/pages/user/realname-auth', 'redirect')
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
